<?php 
class MY_Controller extends CI_Controller{
	
	function MY_Controller(){
  		parent::__construct();
  		$this->load->model('mod_news');
  		$this->load->model('mod_category');
  		@session_start();
  	}
  	
  	function active($table_id){
  		$str_value = explode('-',$table_id);
  		$order = array(
  			'id' => 'desc'
  		);
  		$data = array('status' =>$str_value[2]);
  								
		if($this->mod_lib->update($str_value[0],array('id'=>$str_value[1]),$order,$data)) {
			$this->session->set_flashdata('msview', 'Thay đổi trạng thái thành công '.$str_value[1].' !');
		} else {
			$this->session->set_flashdata('msview', 'Thay đổi trạng thái thất bại '.$str_value[1].' !');
		}
		
		redirect('back_end/'.$str_value[3]);
  	}
  	
	function check_permission (){
		//lay ra id cua user tuong ung
		$admin_id =  $_SESSION['admin_id'];	
		
		//lay ra cac quyen tuong ung voi nguoi quan tri
		$this->db->select('permiss_admins.*,admin_menu.controller');
		$this->db->from('permiss_admins');
		$this->db->join('admin_menu', 'permiss_admins.admin_menu_id = admin_menu.id');
		$this->db->where('admins_id',$admin_id);
		$perrmissUser = $this->db->get()->result_array();
		
		//lay ra controller can truy cap
		$uri_controller = $this->uri->segment(2, 0);
		$uri_action = $this->uri->segment(3, 0);
		
		if ($uri_action == 0) {
			$uri_action = 'index';	
		}
		
		foreach ($perrmissUser as $perrmissUserArr) {
			if($perrmissUserArr['controller'] == $uri_controller && $perrmissUserArr[$uri_action] == 0) {
				$_SESSION['active_redirect'] = '';
				redirect('back_end/backend');	
			}		
		}
	}
	
	function get_link () {
		$SESSION['link_redirect'] = $this->uri->segment(2, 0);
	}
}